package com.atguigu.java;

import org.junit.Test;

public class StringTest {
    @Test
    public void Test1(){
        String s1="abc";
        String s2="abc";
        System.out.println(s1 == s2);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println("**************");
        String s3="abc";
        s3+="def";
        System.out.println(s3);
        System.out.println("***************");
        String s4="abc";
        String s5=s4.replace("a","m");
        System.out.println(s4);
        System.out.println(s5);


    }
    @Test
    public void Test2(){
       String s1="javaEE";
       String s2="javaEE";
       String s3=new String ("javaEE");
       String s4=new String ("javaEE");
        System.out.println(s1 ==s2);
        System.out.println(s1 == s3);
        System.out.println(s1 == s4);
        System.out.println(s3 == s4);
        System.out.println("************");
        Person p1 = new Person("Tom", 12);
        Person p2 = new Person("Tom", 12);
        System.out.println(p1.name.equals(p2.name));
        System.out.println(p1.name == p2.name);
        p1.name="Jerry";
        System.out.println(p2.name);
    }
    @Test
    public void Test3(){
            String s1="javaeebbc";
            String s2="javaee";
            String s3=s2+"bbc";
        System.out.println(s1 == s3);
        final String s4="javaee";
        String s5=s4+"bbc";
        System.out.println(s1==s5);

    }
    @Test
    public void Test4(){
        String s1="javaee";
        String s2="bbc";
        String s3="javaeebbc";
        String s4="javaee"+"bbc";
        String s5=s1+"bbc";
        String s6="javaee"+s2;
        String s7=s1+s2;
        System.out.println(s3 == s4);//true
        System.out.println(s3 == s5);//false
        System.out.println(s3 == s6);//false
        System.out.println(s5 == s6);//false
        System.out.println(s3 == s7);//false
        System.out.println(s5 == s6);//false
        System.out.println(s5 == s7);//false
        System.out.println(s6 == s7);//false

        String s8 = s5.intern();//返回值得到的s8使用的常量值中已经存在的“javaEEhadoop”
        System.out.println(s3 == s8);//true

    }
}
